package com.tyf.common.vo;

import java.util.Map;

/**
 * Description: 根据从表字段去查询主表数据转换VO
 * 	json格式串
 *  {
        idName:"id",		//主表层
        contents:{
                dt1:{		//明细层
                      idName:"id1",
                      contents:{id_eq:"1",text_eq:"2"}
                },
                dt2:{
                      idName:"id2",
                      contents:{id_eq:"1",text_eq:"2"}
                }
        }
	}
 * author:      liutao
 * Createdate:  2016年4月25日上午11:12:10
 * 
 */

public class DetailSearchVO {
	String idName;		//主表关联从表属性
	Map<String, DetailSearchInnerVO> contents;	//从表条件内容,可以有多个
	
	public String getIdName() {
		return idName;
	}

	public void setIdName(String idName) {
		this.idName = idName;
	}

	public Map<String, DetailSearchInnerVO> getContents() {
		return contents;
	}

	public void setContents(Map<String, DetailSearchInnerVO> contents) {
		this.contents = contents;
	}
	
	
	public int getParamsSize(){
		int size =0;
		for(Map.Entry<String, DetailSearchInnerVO> entry : contents.entrySet()){
			DetailSearchInnerVO dvo = entry.getValue();
			size += dvo.getContents()==null ? size:dvo.getContents().size();
		}
		return size;
	}
	
	public boolean checkParamIsExist(String param){
		for(Map.Entry<String, DetailSearchInnerVO> entry : contents.entrySet()){
			DetailSearchInnerVO dvo = entry.getValue();
			Map<String, Object> params = dvo.getContents();
			if(params.containsKey(param)){
				return true;
			}
		}
		return false;
	}
	
	public Map<String, Object> getParamsByDetailName(String detailName){
		DetailSearchInnerVO dvo = contents.get(detailName);
		return dvo.getContents();
	}
	
	public static class DetailSearchInnerVO{
		String idName;		//从表关联主表属性
		Map<String, Object> contents;	//每个从表具体的条件
		
		public String getIdName() {
			return idName;
		}
		public void setIdName(String idName) {
			this.idName = idName;
		}
		public Map<String, Object> getContents() {
			return contents;
		}
		public void setContents(Map<String, Object> contents) {
			this.contents = contents;
		}
		
		
	}
}
